﻿using System;
using Hadlow.Jobvertizer.Models;

namespace Hadlow.Jobvertizer.Tests.Models
{
    public class LocationHelper
    {
        public static Location BuildLocationHierarchy()
        {
            Location all = new Location()
            {
                Id = 1,
                Name = "All",
                Children =
                {
                    new Location() { Id=2, Name="UK", Children = 
                        {
                            new Location() { Id=3, Name="London" },
                            new Location() { Id=4, Name="Brighton" },
                            new Location() { Id=5, Name="Sevenoaks" }
                        }
                    }
                }
            };
            WireUpParents(all);
            return all;
        }

        private static void WireUpParents(Location parent)
        {
            foreach (Location child in parent.Children)
            {
                child.Parent = parent;
                WireUpParents(child);
            }
        }
    }
}
